﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESHOP.UTIL;
using ESHOP.ADMIN.Common;
using ESHOP.DAO;
namespace ESHOP.ADMIN
{
    public partial class TradeLead : Authentication
    {
        private BuyLeadDAO buyDao = new BuyLeadDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CheckPemission())
            {
                Response.Redirect(WebUrlConstants.LOGIN_PAGE, true);
            }
            LoadReferece();
        }
        protected void LoadReferece()
        {
            Bindataforgird();
        }
        protected void Bindataforgird()
        {
            var list = buyDao.Search(txtSearch.Text.Trim());
            GVProducts.DataSource = list;
            GVProducts.DataBind();
            updategrid.Update();
        }
        protected void GVProducts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                var masp = e.CommandArgument.ToString();

                switch (e.CommandName)
                {
                    case "Active":
                        if (!string.Empty.Equals(masp))
                        {
                            var sp = buyDao.Get(masp);
                            if (sp != null)
                            {
                                var result = buyDao.ActiveProduct(sp);
                                if (result == 1)
                                {
                                    Bindataforgird();
                                    lbThongBao.Text = "Đã cho sản phẩm hiển thị lên web site";
                                    Updinfor.Update();
                                    updategrid.Update();
                                }
                                else
                                {
                                    lbThongBao.Text = "Lỗi xảy ra";
                                }
                            }

                        }
                        break;
                    case "DeActive":
                        if (!string.Empty.Equals(masp))
                        {
                            var sp = buyDao.Get(masp);
                            if (sp != null)
                            {
                                var result = buyDao.DeActiveProduct(sp);
                                if (result == 1)
                                {
                                    Bindataforgird();
                                    lbThongBao.Text = "Đã không cho sản phẩm hiển thị lên web site";
                                    updategrid.Update();
                                }
                                else
                                {
                                    lbThongBao.Text = "Lỗi xảy ra";
                                }
                                Updinfor.Update();
                            }

                        }
                        break;
                }
                Bindataforgird();
            }
            catch
            {

                return;
            }

        }
        protected void GVProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            GVProducts.PageIndex = e.NewPageIndex;
            GVProducts.DataBind();
        }

        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            Bindataforgird();
        }
    }
}